---@class UIMythicRank : UIBase
UIMythicRank = UIBase.New(PanelResNames.UIMythicRank)
local t = UIMythicRank

function t.Init()
    UIBase.Init(t)
end

function t:OnCreate()
    self.btnClose = self:GetChild("btnClose")
    self.rankList = self:GetList("ranklist")
    self.my = self:GetChild("my")
    self:RegisterOnClick(self.btnClose,self.ClickClose)
    self:SetDynamicList(self.rankList,self.ItemRender)

    self.poolMgr = ComponentPoolMgr.New(t.RankItem)
    self.myItem = self.poolMgr:GetBindScript(self.my)
    self.datas = nil
end

function t:OnEnable()
    self.rankList.numItems = 0
    NoticeHandler.ReqMainRankInfo(logicMgr.NoticeManager.RankType.mythic,self.GetAllData)
end
function t:OnDisable()
end
function t:OnDestroy()
    if self.poolMgr then
        self.poolMgr:OnDestroy()
    end
    self.datas = nil
    self.poolMgr = nil
    self.myItem = nil
end
function t:Refresh()
    self.rankList.numItems = #self.datas.ranks
    self.myItem:Refresh(self.datas.myRank)
end

function t:ItemRender(index,go)
    local data = self.datas.ranks[index]
    local item = self.poolMgr:GetBindScript(go)
    item:Refresh(data)
end

function t:ClickClose()
    closeUI(PanelResNames.UIMythicRank)
end
function t.GetAllData()
    t.datas = logicMgr.NoticeManager.GetMainRanksByType(logicMgr.NoticeManager.RankType.mythic)
    t:Refresh()
end


t.RankItem = Class("rankItem",UIComponentInterface)
---@class MythicTotalRankPanel_Item : UIComponentInterface
local t_t = t.RankItem
function t_t:OnCreate()
    self.rankText = self:GetChild("rank")
    self.pointText = self:GetChild("point")
    self.nameText = self:GetChild("name")
    self.lvText = self:GetChild("level")
    self.icon = self:GetChild("head/icon/icon")
    self.ctrlNoRank = self:GetController("ctrlNoRank")
    self.ctrlRank = self:GetController("rank")
end
function t_t:OnDestroy()
    self.data = nil
end
function t_t:Refresh(data)
    self.data = data
    self.rankText.text = data.rank
    self.pointText.text = data.param
    self.nameText.text = data.name
    self.lvText.text = data.level
    self:SetPlayerIcon(self.icon,data.headId)
    if data.rank == -1 then
        self.ctrlNoRank.selectedIndex = 1
    else
        self.ctrlNoRank.selectedIndex = 0
        self.ctrlRank.selectedIndex = data.rank >= 4 and 3 or (data.rank-1)
    end
end

return t